<?php
/**
 * 用户积分
 */

namespace app\api\controller;

use app\api\model\PointsRecord;
use app\api\model\User;
use think\Request;

class Points extends  Common
{
   //获取 用户积分 记录
    public function postRecord(Request $request)
    {
        $user_id = $this->checkLoginUser(true);
       // $user_id=74;
        //$user_id=23;
        $t = time();
//        $t=1609430400;
//        $t =1578827328;
        $uptime= $request->post('uptime',$t);
        $record_id = $request->post('record_id',0);
        //$record_id =9769;
        to_json_encode(200,'success',
            PointsRecord::handleRecord(
                PointsRecord::getRecord($user_id,$record_id,$uptime)
            ));
    }
    //获取用户当前积分
    public function postUserPoints(Request $request)
    {
        $user_id = $this->checkLoginUser(true);

        $info = User::getExtendInfo($user_id);
        $user_info = User::getUserInfo($user_id);
        $res=[ 'user_name'=>$user_info['user_name'],
            'user_avatar'=>$user_info['user_avatar']];
        if(empty($info))
        {
            $res['consume_points']='0.00';
            $res['available_points']='0.00';
            $res['invite_code']='';
        }else{
            $res['consume_points']=$info['consume_points'];
            $res['available_points']=$info['available_points'];

            $res['invite_code']=$info['user_invite_code'];
        }
        to_json_encode(200,'success',$res);
    }
}